package com.xiyi.shouxin.dao.user;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

import com.xiyi.shouxin.dao.BaseRepository;
import com.xiyi.shouxin.dao.JdbcPreparedStatement;
import com.xiyi.shouxin.entity.user.Question;
import com.xiyi.shouxin.entity.user.mapper.QuestionMapper;

@Repository
public class QuestionRepository extends BaseRepository<Question> {

    public QuestionRepository() {
        super();
        super.stat = new JdbcPreparedStatement<>(Question.class);
    }

    public List<Question> findByMultiConditionsByPage(Integer status,Sort sort, int page, int size) throws Exception {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (status != null) {
            conditions.add(stat.GetColumnName("status") + " = ? ");
            args.add(status);
        }
        return findByMultiConditionsByPage(conditions, args, sort, page, size, new QuestionMapper());
    }

    public int countByMultiConditions(Integer status) {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (status != null) {
            conditions.add(stat.GetColumnName("status") + " = ? ");
            args.add(status);
        }
        return countByMultiConditions(conditions, args);
    }
}
